分类
联系方式
  1. 新浪微博
  2. E-mail

Dart eval:compileDeclaration

介绍

该方法位于 lib\src\eval\compiler\declaration\declaration.dart,作用是根据不同的 Dart 类型声明,执行不同的编译操作。

具体代码如下:

int? compileDeclaration(Declaration d, CompilerContext ctx,
    {Declaration? parent, int? fieldIndex, List<FieldDeclaration>? fields}) {
  if (d is ClassDeclaration) {
    compileClassDeclaration(ctx, d);
  } else if (d is MethodDeclaration) {
    return compileMethodDeclaration(d, ctx, parent as NamedCompilationUnitMember);
  } else if (d is FunctionDeclaration) {
    compileFunctionDeclaration(d, ctx);
  } else if (d is FieldDeclaration) {
    compileFieldDeclaration(fieldIndex!, d, ctx, parent as ClassDeclaration);
  } else if (d is ConstructorDeclaration) {
    compileConstructorDeclaration(ctx, d, parent as ClassDeclaration, fields!);
  } else if (d is VariableDeclaration) {
    compileTopLevelVariableDeclaration(d, ctx);
  } else {
    throw CompileError('No support for ${d.runtimeType}');
  }
}

其中的声明均为 Dart Analyzer 中提供:

  • ClassDeclaration
  • MethodDeclaration
  • FunctionDeclaration
  • FieldDeclaration
  • ConstructorDeclaration
  • VariableDeclaration